import http from "@/utils/request/httpRequest.ts";
import type { ListPagination, ListType } from "@/types/commonType.ts";
import type { DictListType, DictAddType, DictEditType, DictChildListType, DictChildAddType, DictChildEditType } from "@/types/dictionary"

// 父级分页列表
export const dictionaryList = (data: ListPagination & {
    dictCode: string,
    dictName: string,
}) => http.post<ListType<DictListType[]>>('sys/dict/getDictList', data)

// 父级添加
export const AddDictionary = (data: DictAddType) => http.post('sys/dict/add', data)

// 删除
export const DelDictionary = (data: object) => http.post("sys/dict/deleteBatch", data)

// 编辑
export const EditDictionary = (data: DictEditType) => http.post("sys/dict/update", data)

// 导出
export const exportXls = (data: object) => http.post("sys/dict/exportXls", {
    responseType: 'blob',
    data
},)

// 导入
// 子级列表
export const childList = (data: ListPagination & {
    itemText: string, //名称
    status: number //状态 1启用 0不启用
}) => http.post<ListType<DictChildListType[]>>("sys/dictItem/getDictItemList", data)

// 添加
export const AddChild = (data: DictChildAddType) => http.post('sys/dictItem/add', data)

// 编辑
export const EditChild = (data: DictChildEditType) => http.post("sys/dictItem/update", data)

// 删除
export const DelChild = (data: object) => http.post("sys/dictItem/deleteBatch", data)


//  下载导入模板
export const downLoad = (data:object) => http.get("file/downloadTemplate", {
    responseType: "blob",
    params: data
})
